﻿<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
$url = $this->baseurl.'/images/com_retailshop/';	
?>	
<?php 	
	$caregory = '';
	/*for($i = 0 ; $i < count($this->catagorys_Menu); $i++){
		if($i!=3)
			$caregory .= '<li><a href="index.php?option=com_retailshop&view=home&task=detailscatelog&id='.$this->catagorys_Menu[$i]->id.'">'.$this->catagorys_Menu[$i]->name.'</a></li>';
		else{
			$caregory .= '<li class="last"><a href="index.php?option=com_retailshop&view=home&task=detailscatelog&id='.$this->catagorys_Menu[$i]->id.'">'.$this->catagorys_Menu[$i]->name.'</a></li>';
			break;
		}
	}*/
?>	
	<div id="main">
    	<div class="wrapper wmain">
        	<div id="main-premium">
                
                <div class="main-content">
                	<div id="list-all-deal" class="list">
                    	<div class="head-box">
                        	<h4>List All Deal
                                <?php if(count($this->listdeals) != 0): ?>
								<div class="page-list">
									<span>Page</span>
									  <select name="page" id="limit_product">
										<?php if($this->listdeals != null){ ?>
										<?php for($i = 1; $i <= count($this->listdeals)/9 + 1; $i ++) {?>
											<option value ="<?php echo $i; ?>"><?php echo $i; ?></option>
										<?php } }?>
									</select> 
								</div>
                                <?php endif; ?>
                            </h4>
                        </div>
                        <?php if(count($this->listdeals) == 0): ?>
                            <div class="no-item"><p class="no-product">NO PRODUCTS</p></div>
                        <?php else: ?>        
                        <ul class="product blockwhite" id="listalldealslimit">
						<?php $i = 0; ?>
                            <?php foreach($this->listdeals as $deals) {
								$url_img = ($deals->image_url != '') ? $url."".$deals->image_url : $url."noimages.jpg";
								?>
								<?php $dateAviable = $deals->timetime; ?>
								<li <?php if(($i+1)%3 == 0) echo 'class="last"'; if($i++>=3) echo 'style="margin-top: 10px;"'; ?>>
									<a href="index.php?option=com_retailshop&view=myshop&task=productdetail&shop_id=<?php echo $deals->shop_id; ?>&id=<?php echo $deals->id; ?>"><img src="<?php echo $url_img; ?>" width="200" height="170" /></a>
									<h2 class="product-name">
										<a href="index.php?option=com_retailshop&view=myshop&task=productdetail&shop_id=<?php echo $deals->shop_id; ?>&id=<?php echo $deals->id; ?>"><?php echo $deals->name; ?></a>
									</h2>
									<div class="price-box">
										<p class="price-new">
											<span class="price-label">Price:</span>
											<span class="price" id="product-price"><s><?php echo number_format($deals->price,2); ?> $</s> - <?php echo number_format($deals->sale,2); ?> $</span>
										</p>
									</div>
									<div id="clock_<?php echo $deals->id; ?>" class="clock" style="<?php echo $dateAviable; ?>" >
										  <p>
											<span id="hours_<?php echo $deals->id; ?>"></span>
											Hours
										  </p>
										  <div class="space">:</div>
										  <p>
											<span id="minutes_<?php echo $deals->id; ?>"></span>
											Minutes
										  </p>
										  <div class="space">:</div>
										  <p>
											<span id="seconds_<?php echo $deals->id; ?>"></span>
											Seconds
										  </p>
									</div>
								</li>
								<?php } ?>
                        </ul>
                        <?php endif; ?>
						
                </div>
                
            </div>
           </div> 
          <div id="main-search">
          	<?php echo $this->loadTemplate('left');?>
          </div>
          
       </div>
    </div>
<script type="text/javascript">
	$(document).ready(function(){		
		$("#limit_product").change(function(){			
			var limit =  $(this).val();									
			$.ajax({	
				url:"index.php?option=com_retailshop&view=myshop&task=limitalldeal&value="+limit,
				data:{limit:limit},
				type: "POST",
				dataType: "html",
				success:function(data) {									
					$('#listalldealslimit').html(data);		
					loadAllClock();
				},
				error: function (){
					alert('loi');
				}
			});	
		});		
	});
</script>

<script type="text/javascript" charset="utf-8">
    $(function() {
     
	 loadAllClock();
	 
	 function loadAllClock()
	 {
			$(".clock").each(function(){
				var id = $(this).attr("id");
				var dateAviable = $(this).attr("style");
				dateAviable = Number(dateAviable).valueOf();
				LoadClock(id,dateAviable);
			});
	 }
     
      
		function LoadClock(id,dateAviable)
		{
			var arr = id.split("_");
			var deadl_id = arr[1];
			 var currentDate = new Date();
			  finished = false;	
			$("div#" + id).countdown(dateAviable + currentDate.valueOf(),function(event){
				 $this = $(this);
				switch(event.type) {
  				case "seconds":
  				case "minutes":
  				case "hours":
  				case "days":
  				case "weeks":
  				case "daysLeft":
  				  $this.find('span#'+event.type + "_" + deadl_id).html(event.value);
  				  if(finished) {
  				    $this.fadeTo(0, 1);
  				    finished = false;
  				  }
  					break;
  				case "finished":
				$this.fadeTo('slow', .5);
				finished = true;
  					break;
				}
			});
		}
  		
  		$('select#exampleDate').change(function() {
  		  try {
    		  var $this = $(this),
    		      value;
  		    currentDate = new Date();
    		  switch($this.attr('value')) {
    		    case "other":
    		      value = prompt('Set the date to countdown:\nThe hh:mm:ss parameters are opitionals', 'YYYY/MM/DD hh:mm:ss');
    		      break;
    		    case "daysFromNow":
    		      value = prompt('How many days from now?', '');
    		      value = new Number(value) * 24 * 60 * 60 * 1000 + currentDate.valueOf();
    		      break;
    		    case "minutesFromNow":
    		      value = prompt('How many minutes from now?', '');
    		      value = new Number(value) * 60 * 1000 + currentDate.valueOf();
    		      break;
    		    default:
    		      value = availiableExamples[$this.attr('value')] + currentDate.valueOf();
    		  }
    		  $('div#clock').countdown(value, callback);
    		  $this.find('option:first').attr('selected', true);
    		} catch(e) { alert(e); }
  		});
  	});
  </script>
  <script type="text/javascript">
    $(window).load(function() {
		$('#sub-nav ul').html('<?php echo $caregory; ?>');
    });
    </script>